package com.wc.blue_bridge_history.Java14B.A_幸运数字;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/3/11 9:41
 * @description https://www.lanqiao.cn/paper/3872/problem/3499/
 */
public class Main {
    static int[] f = new int[128];

    public static void main(String[] args) {
        for (int i = 'a', j = 10; i <= 'f'; i++, j++) {
            f[i] = j;
        }
        for (int i = '0', j = 0; i <= '9'; i++, j++) f[i] = j;
        // Integer.toHexString -> 16进制
        // Integer.OctalString -> 8 进制
        int num = 1;
        int idx = 0;
        while (true) {
            if (num % sum(num, 2) == 0 && num % sum(num, 10) == 0 && num % sum(num, 8) == 0 && num % sum(num, 16) == 0) {
                idx++;
                if (idx == 2023) {
                    System.out.println(num);
                    break;
                }
            }
            num++;
        }
    }

    static int sum(int x, int rd) {
        int res = 0;
        while (x > 0) {
            res += x % rd;
            x /= rd;
        }
        return res;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
